home *** CD-ROM | disk | FTP | other *** search
- /* WindowUtilities.c */
- /*
- * WindowUtilities.c
- * Copyright © 1993 Apple Computer Inc. All rights reserved.
- * These functions are called when the window is zoomed or resized.
- */
- #include "DisplayAudit.h"
-
- #ifndef topLeft
- #define topLeft(r) (((Point *) &(r))[0])
- #define botRight(r) (((Point *) &(r))[1])
- #endif
-
- /*
- * DoZoomWindow
- * Algorithm from New Inside Mac (Toolbox Essentials) 4-55
- */
- void
- DoZoomWindow(
- WindowPtr theWindow,
- short whichPart
- )
- {
- GDHandle gd;
- GDHandle gdZoom;
- GrafPtr savePort;
- Rect windowRect;
- Rect zoomRect;
- Rect intersection;
- long thisArea;
- long greatestArea;
- short windowTitleHeight;
- #define PEEK (*((WindowPeek) theWindow))
- #define STATE (**((WStateDataHandle) PEEK.dataHandle))
-
- GetPort(&savePort);
- SetPort(theWindow);
- if (whichPart == inZoomOut) {
- if (gHasColorQuickDraw == FALSE) {
- /*
- * This shouldn't happen on an AOCE system, but,
- * if it does, just force a single screen zoom.
- */
- zoomRect = qd.screenBits.bounds;
- InsetRect(&zoomRect, 4, 4);
- STATE.stdState = zoomRect;
- }
- else {
- /*
- * We have color QuickDraw. Locate the screen that contains
- * the largest area of the window and zoom to that screen.
- */
- windowRect = theWindow->portRect;
- LocalToGlobal(&topLeft(windowRect));
- LocalToGlobal(&botRight(windowRect));
- windowTitleHeight = windowRect.top
- - 1
- - (**PEEK.strucRgn).rgnBBox.top;
- windowRect.top -= windowTitleHeight;
- greatestArea = 0;
- gdZoom = NULL;
- /*
- * Look at all graphics devices and find an intersection. Then
- * select the largest intersecting screen.
- */
- for (gd = GetDeviceList(); gd != NULL; gd = GetNextDevice(gd)) {
- if (TestDeviceAttribute(gd, screenDevice)
- && TestDeviceAttribute(gd, screenActive)
- && SectRect(&windowRect, &(**gd).gdRect, &intersection)) {
- thisArea = ((long) width(intersection))
- * ((long) height(intersection));
- if (thisArea > greatestArea) {
- greatestArea = thisArea;
- gdZoom = gd;
- }
- }
- }
- /*
- * If we're zooming to the device with the menu bar,
- * allow for its height.
- */
- if (GetMainDevice() == gdZoom)
- windowTitleHeight += GetMBarHeight();
- zoomRect = (**gdZoom).gdRect;
- InsetRect(&zoomRect, 3, 3);
- zoomRect.top += windowTitleHeight;
- STATE.stdState = zoomRect;
- } /* End if color QuickDraw */
- } /* End if zoom out */
- ZoomWindow(theWindow, whichPart, (theWindow == FrontWindow()));
- /*
- * Zoom redraws the entire window.
- */
- EraseRect(&theWindow->portRect);
- InvalRect(&theWindow->portRect);
- SetPort(savePort);
- #undef PEEK
- #undef STATE
- }
-
- /*
- * DoGrowWindow
- * Algorithm from New Inside Mac (Toolbox Essentials) 4-58
- * We assume that the window can cover the entire screen.
- */
- Boolean
- DoGrowWindow(
- WindowPtr theWindow,
- short minimumWidth,
- short minimumHeight
- )
- {
- long growSize;
- Rect limitRect;
- Rect viewRect;
- RgnHandle localUpdateRgn;
-
- limitRect.left = minimumWidth;
- limitRect.top = minimumHeight;
- limitRect.right = qd.screenBits.bounds.right;
- limitRect.bottom = qd.screenBits.bounds.bottom;
- growSize = GrowWindow(theWindow, EVENT.where, &limitRect);
- if (growSize != 0) {
- #if 0 /* This doesn't quite work right */
- /*
- * Window size changed. Get our update region in
- * local coordinates.
- *
- * viewRect is our "real" content area.
- */
- viewRect = theWindow->portRect;
- localUpdateRgn = NewRgn();
- CopyRgn(((WindowPeek) theWindow)->updateRgn, localUpdateRgn);
- OffsetRgn(
- localUpdateRgn,
- theWindow->portBits.bounds.left,
- theWindow->portBits.bounds.top
- );
- #else
- #pragma unused (viewRect, localUpdateRgn)
- #endif
- SizeWindow(theWindow, LoWord(growSize), HiWord(growSize), TRUE);
- /*
- * Force a redraw of the entire window, but exclude the
- * intersection of the old view rect and the new view rect.
- * Invalidate any prior update region in any case.
- */
- EraseRect(&theWindow->portRect);
- InvalRect(&theWindow->portRect);
- #if 0
- (void) SectRect(&viewRect, &theWindow->portRect, &viewRect);
- ValidRect(&viewRect);
- InvalRgn(localUpdateRgn);
- DisposeRgn(localUpdateRgn);
- #endif
- }
- return (growSize != 0);
- }
-
-